package com.fupeng.leetCode;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class MissingRange {

	public static void main(String[] args) {
		int[] T={1,3,50,75};
		System.out.println(Arrays.toString(solution(T,0,99)));
	}

	private static String[] solution(int[] t,int start,int end) {
		if(end-start+1==t.length)
			return null;
		List<String>list = new ArrayList<String>();
		if(t.length==0){
			for(int i=start;i<=end;i++)
				list.add(String.valueOf(i));
			return list.toArray(new String[list.size()]);
		}
		for(int i=0;i<t.length;i++){
			if(t[0]>start){
				addRange(list, start-1, t[0]);
			}
			int temp = t[i]-start;
			if(temp>2){
				addRange(list,start,t[i]);
			}
			start=t[i];
		}
		if(t[t.length-1]<end)
			addRange(list, t[t.length-1], end+1);
		return list.toArray(new String[list.size()]);
	}

	private static void addRange(List<String> list, int from, int to) {
		if(to-from==2)
			list.add(String.valueOf(from+1));
		else
			list.add(String.valueOf(from+1)+"->"+String.valueOf(to-1));
	}

}
